#include "DirectLoader.h"

namespace re
{
	namespace io
	{
		
		U32 DirectLoader::LoadFile(const std::wstring & filename, const std::wstring * virtualfn, char ** buffer)
		{
			if(virtualfn != 0)
			{
				*buffer = 0;
				return 0;
			}
			std::ifstream file(filename, std::ios::binary);
			if(!file.is_open())
			{
				*buffer = 0;
				return 0;
			}
			U32 size = 0;
			file.seekg(0, std::ios::end);
			size = file.tellg();
			file.seekg(0, std::ios::beg);

			if(size == 0)
			{
				*buffer = 0;
				return 0;
			}

			*buffer = new S8[size];

			file.read(*buffer, size);

			file.close();
			return size;
		}
		bool DirectLoader::FileExist(const std::wstring & realfile, const std::wstring * virtualfn)
		{
			if(virtualfn != 0)
			{
				return false;
			}
			std::ifstream file(realfile);
			if(file.is_open())
			{
				file.close();
				return true;
			}
			return false;
		}
	}
}